import request from './request.js'
let token = wx.getStorageSync("token") == undefined ? "" : wx.getStorageSync("token");

class Http {

    constructor() {
         this._baseUrl = 'https://xxg.xjdio.com/api/Zxrh.Xncf.Xxgmall' //生产'
        // this._baseUrl = 'https://192.168.1.110:44311/api/WeChat_MiniProgram' //测试网
        // this._baseUrl = 'https://x0s20sdb-44311.asse.devtunnels.ms/' //测试网
      //  this._baseUrl = 'https://localhost:44311/api/Zxrh.Xncf.Xxgmall' //测试网
        this._defaultHeader = {
            // "content-type": 'application/json; charset=utf-8',
            'Authorization': 'Bearer ' + token
        }
        this._request = new request
        this._request.setErrorHandler(this.errorHander)
    }

    /**
     * 统一的异常处理方法
     */
    errorHander(res) {
        console.error(res)
    }
    /**
     * 调用请求
     */
    post(url, data) {
        let token = wx.getStorageSync('token');
        this._defaultHeader = {
            'Authorization': 'Bearer ' + token
        }

        return this._request.postRequest(this._baseUrl + url, data, this._defaultHeader).then(res => res.data)
    }

    get(url, data) {
        let token = wx.getStorageSync('token');
        this._defaultHeader = {
            //   'Authorization': 'Bearer ' + token
            "content-type": 'application/json; charset=utf-8',
        }
        return this._request.getRequest(this._baseUrl + url, data, this._defaultHeader).then(res => res.data)
    }
}

export default Http